package com.jlnk.androidfmc.presenter;

import androidx.fragment.app.Fragment;

import com.jlnk.androidfmc.fragment.BuyerFragment;
import com.jlnk.androidfmc.fragment.SellerFragment;
import com.jlnk.androidfmc.view.MainView;

public class MainPresenterImpl implements MainPresenter {
    private MainView view;
    private SellerFragment sellerFragment;
    private BuyerFragment buyerFragment;
    private boolean isBuyFragmentVisible = true;

    public MainPresenterImpl(MainView view, SellerFragment sellerFragment, BuyerFragment buyerFragment) {
        this.view = view;
        this.sellerFragment = sellerFragment;
        this.buyerFragment = buyerFragment;
    }

    @Override
    public void onToggleClick() {
        isBuyFragmentVisible = !isBuyFragmentVisible;
        Fragment newFragment = isBuyFragmentVisible ? buyerFragment : sellerFragment;
        view.displayFragment(newFragment);
        view.setToggleText(isBuyFragmentVisible ? "去卖货" : "去买货");
    }
}